Getting a config parser

The pypmj-module uses a configuration file in which all information about the JCMsuite-installation, data storage, servers and so on are set. This makes pypmj very flexible, as you can generate as many configuration files as you like. Here, we show how to easily set up your configuration using the config_tools shipped with pypmj.

We first import the config_tools.


In [ ]:
import config_tools as ct

We can get a suitable config parser for convenient setting of our preferences.


In [ ]:
config = ct.get_config_parser()

This parser already contains some default values and the standard sections:


In [ ]:
config.sections()

We will go through the different sections and show which values can to be set.

Note: If a configuration option is not set, a default value will be used by pypmj. So you only need to uncomment and set the options that you like.

Sections

User

Set your e-mail address here if you like to receive status e-mail.


In [ ]:
# config.set('User', 'email', 'your_address@your_provider.com')

Storage

Set up a base folder into which all the simulation data should be stored. The SimulationSet class of pypmj offers a convenient way to organize your simulations inside this folder. You can also set the special value 'CWD', which will cause that current working directory will be used instead.


In [ ]:
# config.set('Storage', 'base', '/path/to/your/global/storage/folder')

Data

To keep your projects in one place, you can set a global projects folder. If you initialize a JCMProject unsing the JCMProject-class of pypmj, you can then give the path to your project relative to this directory. pypmj will leave the contents if these folders untouched and copy the contents to a working directory. If you don't like to use a global folder, you can also pass absolute paths to JCMProject.


In [ ]:
# config.set('Data', 'projects', 'project/collection/folder')

Note: Be sure that this path is set to the project-folder shipped with pypmj to successfully run the Using pypmj - the mie2D-project notebook.

If you are using the materials-extension of pypmj, a RefractiveIndex database is needed and the path is configured here. Please contact one of the maintainers of pypmj for info on such a database.


In [ ]:
# config.set('Data', 'refractiveIndexDatabase', '/path/to/your/RefractiveIndex/database')

JCMsuite

It is assumed that your installation(s) of JCMsuite are in a fixed directory, which is configured using the root key. That way, you can change the version of JCMsuite to use easily by only changing the directory name with the key dir. Some versions of JCMsuite provide different kernels, which can be set using the kay kernel.


In [ ]:
config.set('JCMsuite', 'root', '/path/to/your/parent/CJMsuite/install/dir')
config.set('JCMsuite', 'dir', 'JCMsuite_X_Y_Z') # <- this is simply the folder name
config.set('JCMsuite', 'kernel', 3)

Logging

For the logging, you can specify the logging level ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', or 'NOTSET'), whether or not to write a log-file and if status mails should be send by the run_simusets_in_save_mode utility function. For the latter, you further need to configure the mail server used by smtplib.SMTP .


In [ ]:
# config.set('Logging', 'level', 'INFO')
# config.set('Logging', 'write_logfile', True)
# config.set('Logging', 'log_directory', 'logs') # <- can be a relative or an absolute path
# config.set('Logging', 'log_filename', 'from_date')
# config.set('Logging', 'send_mail', True)
# config.set('Logging', 'mail_server', 'localhost')

Adding servers

Finally, you can add one or more servers which can be used by the JCMdaemon. Have a look at the doc string to see the possible configurations:


In [ ]:
ct.add_server?

Minimally, the localhost needs to be added, because otherwise there will be no resources for the JCMdaemon. This is done by using 'localhost' as the hostname and your local username as the login:


In [ ]:
# ct.add_server(config, 'localhost', 
#               multiplicity_default=1,
#               n_threads_default=1)

But you may have additional server power. Let's assume you have installed JCMsuite on a server called myserver which you can reach via ssh by typing ssh YOUR_LOGIN@myserver.something.com. The directory into which your JCMsuite version(s) is(are) installed may be /path/on/server/to/your/jcm_installations. The JCMsuite directory name needs to be the same as configured in the section JCMsuite under key dir! You may further want to set a nickname to manage all your servers later more easily, e.g. myserver. Finaly, you want to set 6 workers and 6 threads per worker as a default. Then just write:


In [ ]:
# ct.add_server(config, 'myserver.something.com', 'YOUR_LOGIN', 
#               JCM_root='/path/on/server/to/your/jcm_installations',
#               multiplicity_default=6,
#               n_threads_default=6,
#               nickname='myserver')

Note: You will need a password free login to these servers.

Saving the configuration file

So you are done and all that is left is saving the configuration to a config file:


In [ ]:
ct.write_config_file(config, 'config.cfg')

Using the configuration file with pypmj

Using a specific configuration file is easily done by setting the environment variable 'PYPMJ_CONFIG_FILE'. If this is not set, pypmj will look for a config.cfg in the current working directory. Setting the environment variable can be done using the os module:


In [ ]:
import os
os.environ['PYPMJ_CONFIG_FILE'] = '/path/to/your/config.cfg'

Now run the test_base.py in the tests folder. This will also check your configuration file. After that, look into the Using pypmj - the mie2D-project notebook in the examples directory to get started with pypmj.